#include "Message.h"
#include <pthread.h>

using namespace std;

pthread_mutex_t	msgCount_lock;
//pthread_mutex_init(&msgCount_lock, NULL);

int msgCount = 0 ;

Message::Message(int source, int target) : source(source), target(target)
{
	pthread_mutex_lock(&msgCount_lock);
	msgCount++;
	pthread_mutex_unlock(&msgCount_lock);
}

Message::~Message()
{
	pthread_mutex_lock(&msgCount_lock);
	msgCount--;
	pthread_mutex_unlock(&msgCount_lock);
}

int getMsgCount(){
	int ans;
	pthread_mutex_lock(&msgCount_lock);
	ans=msgCount;
	pthread_mutex_unlock(&msgCount_lock);
	return ans;
}
ostream& operator<< ( std::ostream& output, const Message& t) {
	return output << "Messsage (" << t.source << "," << t.target << ")" ;
}
